package org.example.controller;


import org.example.domain.FruitInbound;
import org.example.domain.FruitInventory;
import org.example.response.ApiResponse;
import org.example.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/***
 * 库存
 */
@RestController
@RequestMapping("/api/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    /**
     * 获取库存列表
     */
    @GetMapping("/list")
    public ApiResponse<Map<String,Object>> getInventoryList(
            @RequestParam(required = false) String fruitName,
            @RequestParam(required = false) String inventoryStatus,
            @RequestParam(required = false) String inventoryType,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            List<FruitInventory> list = inventoryService.getInventoryList(fruitName, inventoryType,inventoryStatus,pageNum, pageSize);
            HashMap<String, Object> returnMap = new HashMap<>();
            returnMap.put("total",2);
            returnMap.put("list",list);
            return ApiResponse.success(returnMap);
        } catch (Exception e) {
            return ApiResponse.error(500, "获取库存列表失败：" + e.getMessage());
        }
    }
}
